package com.honeywen.mymvc.leetcode;

/**
 * 206. 反转链表
 * https://leetcode-cn.com/problems/reverse-linked-list/
 * @author wangwei
 * @date 2019/3/2
 */
public class ReverseList {

    public static void main(String[] args) {

    }

    public ListNode reverseListRecursion(ListNode head) {
        if (head == null) {
            return head;

        }

        ListNode newHead = recursion(head);
        head.next = null;
        return newHead;
    }

    private ListNode recursion(ListNode p) {
        if (p.next == null) {
            return p;
        } else {
            ListNode next = p.next;
            ListNode newHead = recursion(next);
            next.next = p;
            return newHead;
        }

    }


}
